                                                                                                                                                                                                                                                                             *additional sims vars


# delimit ;
set more off;

local raw "$raw\SIMS";
local saves "$raw\saves";
cd "`raw'";



foreach yy in 02 03 04 05 06  07{;
use "`raw'\simseoy`yy'.dta", clear;
rename *, lower ;
keep if grade=="12";
keep plan  sasid;

gen year=20`yy';
destring sasid, replace;

duplicates drop;
compress;
save "`saves'\extra`yy'.dta", replace;
};



foreach yy in 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22{;
use "`raw'\simseoy`yy'.dta", clear;
rename *, lower ;
keep if grade=="12";
keep plan grad_core sasid;

gen year=20`yy';
destring sasid, replace;

duplicates drop;
compress;
save "`saves'\extra`yy'.dta", replace;
};
#delimit;
use "$saves\extra02.dta", clear;
foreach yy in  03 04 05 06  07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22{;

append using "$saves\extra`yy'";
};

g byte mass_core_grad = grad_core=="01";
replace mass_core_grad= . if grad_core=="";

g byte plans_4yr=(plan=="01"|plan=="03") ;
g byte plans_2yr=(plan=="02"|plan=="04");

*replace plans_4=. if plan=="500";
*replace plans_2=. if plan=="500";
	format sasid %12.0f;
	
*ever mass_core_grad;
bys sasid: egen ever_mass_core_grad=max(mass_core_grad) if mass_core_grad!=.;
* last plans;
bys sasid: egen max = max(year);
keep if year==max;
drop max;

drop plan  grad_core mass_core;
	#delimit;

foreach v of varlist plans* {;
	bys sasid: egen max`v' = max(`v');
	replace `v'=max`v';
};
drop max*;
duplicates drop;

save "$data_clean/extra_sims.dta", replace;

